package com.huazai.ServletStudy;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

@WebServlet(name = "Demo02", value = "/Demo02")
public class ServletDemo02 extends GenericServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {

        //获取ServletContext对象
        servletResponse.setContentType("text/html;charset = UTF-8");
        PrintWriter pw = servletResponse.getWriter();
//        pw.print("<br>");
//
//        ServletContext application = this.getServletContext();
//        Enumeration<String> names = application.getInitParameterNames();
//        while( names.hasMoreElements() ) {
//            String name = names.nextElement();
//            String value = application.getInitParameter(name);
//            pw.print("属性名为 " + name);
//            pw.print("属性值为 " + value);
//            pw.print("<br>");
//        }

//        String relativePath = application.getContextPath();
//        pw.print(relativePath);
//        pw.print("<br>");
//        String realPath = application.getRealPath("/WEB-INF/web.xml");
//        pw.print(realPath + "<br>");

        //log
        //这个日志会记录到CATALINA_HOME/logs 的目录下
//        application.log("你们好，我想跟lyt在一起！！！为此，我要努力");
//
//        int age = 17;
//        if ( age < 18) {
//            application.log("对不起，未成年，请不要进来。", new RuntimeException("小屁孩，快离开!"));
//        }


//        User userZZH = new User("","123");
//        application.setAttribute("user01",userZZH);
//        User user01 = (User) application.getAttribute("user01");
//        pw.print(user01 + "<br>");
//
//
//        application.setAttribute("name","！！！");
//        String name = (String) application.getAttribute("name");
//        pw.print(name);

        pw.print("<h1>转发。。。</h1>");





    }
}
